
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * This class is handle exception UI
 */
public class HandleExUI extends JPanel {
	/**
	 * title for the current window  
	 */
	private JLabel lbltitle = null;
	/**
	 * get data button 
	 */
	private JButton btnGetData;
	/**
	 * handle exception  button 
	 */
	private JButton btnHandleEx;
	/**
	 * back button 
	 */
	public JButton btnBack = null;
	/**
	 * help button 
	 */
	public JButton btnHelp = null;
	/**
	 * save the current panel for the "back" function 
	 */
	private JPanel curPanel;
	public SpecialTeacher CHT;
	public SpecialAdd ADD;
	public SpecialRemove RMV;
	

	
	
	public HandleExUI () {
		super();
		initialize();
	}

	private void initialize() {
		curPanel = this;

		this.setVisible(true);
		this.setVisible(true);

		lbltitle = new JLabel("Manager window");
		lbltitle.setBounds(187, 28, 110, 14);

		this.setSize(400, 321);
		this.setLayout(null);
		
		this.add(lbltitle);
	
		btnBack = new JButton("Back");
		btnBack.setBounds(187, 253, 86, 25);
		this.add(btnBack,null);
		this.setVisible(true);
		
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Click on one of the option");
				  System.out.println("user press Help button");
			}
		});
		this.add(btnHelp,null);
		
		JButton btnAddStudents = new JButton("Add Students");
		btnAddStudents.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SQL s = new SQL(null,28);
				s.accept();
				//System.out.println("TEMP MSG   " + Global.chat.temp);
				Object msg = s.getMsg();
				//System.out.println("MSG   " + msg.toString());
								
				if (msg.equals("NoExceptions")) // No Exception
				{
					ADD = new SpecialAdd();
				}
				else // Receive Exceptions
				{
					System.out.println("Receive Exception " + msg.toString());	
					ADD = new SpecialAdd(msg);
				}
				setVisible(false);
				System.out.println("Add students by manager");
				Global.main.setContentPane(ADD);
				ADD.btnBack.addActionListener(new ActionListener() {   //back from HandleEx UI
					public void actionPerformed(ActionEvent arg0) {
						Global.main.setContentPane(curPanel);
							curPanel.setVisible(true);
							}
						});
			}
		});
		btnAddStudents.setBounds(160, 134, 150, 25);
		add(btnAddStudents);
		
		JButton btnRemoveStudent = new JButton("Remove Student");
		btnRemoveStudent.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SQL s = new SQL(null,29);
				s.accept();
				//System.out.println("TEMP MSG   " + Global.chat.temp);
				Object msg = s.getMsg();
				//System.out.println("MSG   " + msg.toString());
								
				if (msg.equals("NoExceptions")) // No Exception
				{
					RMV = new SpecialRemove();
				}
				else // Receive Exceptions
				{
					System.out.println("Receive Exception " + msg.toString());	
					RMV = new SpecialRemove(msg);
				}
				setVisible(false);
				System.out.println("Remove students by manager");
				Global.main.setContentPane(RMV);
				RMV.btnBack.addActionListener(new ActionListener() {   //back from HandleEx UI
					public void actionPerformed(ActionEvent arg0) {
						Global.main.setContentPane(curPanel);
							curPanel.setVisible(true);
							}
						});
					}
				});
		btnRemoveStudent.setBounds(160, 84, 150, 25);
		add(btnRemoveStudent);
		
		JButton btnChangeTeacher = new JButton("Change Teacher");
		btnChangeTeacher.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SQL s = new SQL(null,27);
				s.accept();
				//System.out.println("TEMP MSG   " + Global.chat.temp);
				Object msg = s.getMsg();
				//System.out.println("MSG   " + msg.toString());
								
				if (msg.equals("NoExceptions")) // No Exception
				{
					CHT = new SpecialTeacher();
				}
				else // Receive Exceptions
				{
					System.out.println("Receive Exception " + msg.toString());	
					CHT = new SpecialTeacher(msg);
				}
				
				setVisible(false);
				System.out.println("Change Teacher by manager");
				Global.main.setContentPane(CHT);
				CHT.btnBack.addActionListener(new ActionListener() {   //back from HandleEx UI
					public void actionPerformed(ActionEvent arg0) {
						Global.main.setContentPane(curPanel);
							curPanel.setVisible(true);
							}
						});
			}
		});
		btnChangeTeacher.setBounds(160, 184, 150, 25);
		add(btnChangeTeacher);
		this.setVisible(true);
		
	}
}

